package cn.yr.blog.controller.management;

import cn.yr.blog.service.TagService;
import cn.yr.common.core.domain.entity.YrTag;
import cn.yr.common.core.domain.vo.PageVo;
import cn.yr.common.exception.ret.Ret;
import cn.yr.common.security.annotation.PreAuthorize;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;


/**
 * 标签
 * @author Lang 1102076808@qq.com
 * @date 2020-07-18 22:55:37
 */
@Api(tags = "management标签")
@RestController
@RequestMapping("/management/tag")
public class ManagerTagController {
    @Autowired
    private TagService tagService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    @PreAuthorize(hasPermi = "manager:tag:page")
    public Ret page(@RequestBody PageVo<YrTag> pageVo){
    	PageVo<YrTag> pageTag = tagService.page(pageVo,new QueryWrapper<>());
	    return Ret.success(pageTag);
    }

    /**
     * @author Lang
     * @date 2020/7/18 23:10
     */
    @RequestMapping("/list")
    @PreAuthorize(hasPermi = "manager:article:add")
     public Ret list(){
	     List<YrTag> list = tagService.list();
	     return Ret.success(list);
     }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @PreAuthorize(hasPermi = "manager:tag:info")
    public Ret info(@PathVariable("id") Integer id){
		YrTag yrTag = tagService.getById(id);
	    return Ret.success(yrTag);
    }

    /**
     * 保存
     */
    @RequestMapping("/add")
    @PreAuthorize(hasPermi = "manager:tag:add")
    public Ret save(@Validated @RequestBody YrTag yrTag){
		tagService.save(yrTag);
	    return Ret.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/edit")
    @PreAuthorize(hasPermi = "manager:tag:edit")
    public Ret update(@Validated @RequestBody YrTag yrTag){
		tagService.updateById(yrTag);
	    return Ret.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/remove/{ids}")
    @PreAuthorize(hasPermi = "manager:tag:remove")
    public Ret delete(@PathVariable Integer[] ids){
		tagService.removeByIds(Arrays.asList(ids));
        return Ret.success();
    }

}
